package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.api.entity.MallCommodityCategory;
import com.alpha.eceasy.mall.api.vo.MallCommodityCategoryVO;
import com.alpha.eceasy.mall.service.impl.MallCommodityCategoryServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 商品品类表
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/commodity-category")
@Tag(description = "commodity-category", name = "商品品类表")
public class MallCommodityCategoryController {

    private final MallCommodityCategoryServiceImpl mallCommodityCategoryService;

    /**
     * 分页查询
     *
     * @param mallCommodityCategory 商品品类
     * @return 分页结果
     */
    @Operation(description = "分页查询", summary = "分页查询")
    @GetMapping("")
    public R<IPage<MallCommodityCategoryVO>> getMallCommodityCategoryVOPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNumber,
                                                                            @RequestParam(value = "pageSize", required = false, defaultValue = "10000") Integer pageSize,
                                                                            MallCommodityCategory mallCommodityCategory) {
        return R.ok(mallCommodityCategoryService.getMallCommodityCategoryVOPage(Page.of(pageNumber, pageSize), mallCommodityCategory));
    }

    /**
     * 通过id查询商品品类
     *
     * @param id id
     * @return R 查询结果
     */
    @Operation(description = "通过id查询", summary = "通过id查询")
    @GetMapping("/{id}")
    public R<MallCommodityCategory> getById(@PathVariable("id") Long id) {
        return R.ok(mallCommodityCategoryService.getById(id));
    }

    /**
     * 新增商品品类
     *
     * @param mallCommodityCategory 商品品类
     * @return R 返回结果
     */
    @Operation(description = "新增商品品类", summary = "新增商品品类")
    //@SysLog("新增商品品类")
    @PostMapping
    public R<Boolean> save(@RequestBody MallCommodityCategory mallCommodityCategory) {
        return R.ok(mallCommodityCategoryService.save(mallCommodityCategory));
    }

    /**
     * 修改商品品类
     *
     * @param mallCommodityCategory 商品品类
     * @return R 返回结果
     */
    @Operation(description = "修改商品品类", summary = "修改商品品类")
    //@SysLog("修改商品品类")
    @PutMapping
    public R<Boolean> updateById(@RequestBody MallCommodityCategory mallCommodityCategory) {
        return R.ok(mallCommodityCategoryService.updateById(mallCommodityCategory));
    }

    /**
     * 删除商品品类
     *
     * @param id id
     * @return R 返回结果
     */
    @Operation(description = "通过id删除商品品类", summary = "通过id删除商品品类")
    //@SysLog("通过id删除商品品类")
    @DeleteMapping("/{id}")
    public R<Boolean> removeById(@PathVariable String id) {
        return R.ok(mallCommodityCategoryService.removeById(id));
    }
}
